﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head><link rel="stylesheet" href="${ctx}/common/common.css">
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all">
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
    
    <script src="${ctx}/common/plugins/layuiadmin/layui-xtree/layui-xtree.js"></script>
</head>
<body>
<form class="layui-form">
<input type="hidden" id="roleId" value="${roleId}">
<div class="layui-col-md12">
	<div class="proclashow" style="width: 99%; position: absolute; background: white; z-index: 10; border-right: 1px solid rgb(231, 231, 231); border-bottom: 1px solid rgb(231, 231, 231); border-left: 1px solid rgb(231, 231, 231); border-image: initial; border-top: none">
		<!-- <ul id="proclaTree"></ul> -->
		<div id="functionTree" class="xtree_contianer">
		</div>
		<!-- <button class="layui-btn" id="formBtn" style="padding: 0 10px;height: 30px;line-height: 30px;float: right;margin: 20px">立即提交</button> -->
	</div>
</div>

</form>

<script>
    layui.use(['form','tree','layer'],function(){
    	var $ = layui.$,layer = layui.layer,form=layui.form,tree=layui.tree;
        /* 生产范围树 */
        var url = '${ctx}/role/queryFunctionTree';
   		$.ajax({
   			type:"post",	//数据传输方式
   			url : url,		//请求路径
   			data: {roleId:$("#roleId").val()},
   			dataType:"json",	//预期服务器返回的数据类型 text,json
   			scriptCharset: 'utf-8',
   			async:false,
   			success:function(msg){
   				xtree1 = new layuiXtree({
   		            elem: 'functionTree',   //(必填) 放置xtree的容器，样式参照 .xtree_contianer
   		            form: form,    //(必填) layui 的 from
   		            data: msg,	//(必填) json数据
   		         	ckall: true,	//启用全选功能，默认值：false
   		         	isopen: true	//加载完毕后的展开状态，默认值：true
   		        });
   				xtree1.render();
   			}
   		});
   		
   		
    })
    
    function formData(){
    	parsonValue = new Array();
  		/* 获取生产范围树选中数据 */
      	var fIds = new Array();
      	var proclaArray = xtree1.GetChecked();
        for (var i = 0; i < proclaArray.length; i++) {
       		fIds.push(proclaArray[i].value);
       		findParent(proclaArray[i].value);
        }
       var ids = '';
       if(proclaArray.length == 0){
    	   ids = fIds.toString();
       }else{
    	   ids = fIds.toString() +','+parsonValue.toString();
       }
       return ids;
 	};
 	var parsonValue = new Array();
 	function findParent(childrenId){
 		var pObj = xtree1.GetParent(childrenId);
 		var pValue = '';
 		if(pObj != null){
 			pValue = pObj.value;
 			parsonValue.push(pValue);
 			findParent(pValue)
 		}
 	}
</script>
</body>
</html>



